package com.isoft.dailymanprovidor.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isoft.dailymanprovidor.bean.ResponseData;
import com.isoft.dailymanprovidor.bean.ResultCode;
import com.isoft.dailymanprovidor.dao.MeetingSignDao;
import com.isoft.dailymanprovidor.entity.MeetingSign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MeetingSignService {
    @Autowired
    MeetingSignDao meetingSignDao;
    //分页获取会议招待信息
    public ResponseData getallPage(Integer currentPage, Integer size, String date,String leader,String department){
        ResponseData responseData = new ResponseData();
        Page<MeetingSign> meetingSignPage=new Page<>();
        String time="2010-09-30 16:00:00";
        // 初始化分页参数
        if (currentPage == null){
            currentPage = 1;
        }
        if (size == null){
            size =10;
        }
        //构造查询条件
        meetingSignPage.setCurrent(currentPage).setSize(size);
        QueryWrapper<MeetingSign> wrapper=new QueryWrapper<>();
        wrapper.like("leader",leader);
        wrapper.like("department",department);
        if (date==null||date.isEmpty()){
            wrapper.gt("date",time);
        }else {
            wrapper.eq("date",date);
        }
        //构造返回Controller 的结果
        responseData.setErrorCode(ResultCode.SUCCESS.getCode());
        responseData.setMsg(ResultCode.SUCCESS.getMessage());
        responseData.setData(meetingSignDao.selectPage(meetingSignPage,wrapper));
        return responseData;
    }
    //新增会议招待
    public boolean addmeetingsign(MeetingSign meetingSign){
        return meetingSignDao.addmeetingsign(meetingSign)>0;
    }
    //修改会议招待信息
    public boolean updatemeetingsign(MeetingSign meetingSign){
        UpdateWrapper<MeetingSign> wrapper=new UpdateWrapper<>();
        wrapper.set("leader",meetingSign.getLeader());
        wrapper.set("department",meetingSign.getDepartment());
        wrapper.set("location",meetingSign.getLocation());
        wrapper.set("date",meetingSign.getDate());
        wrapper.set("content",meetingSign.getContent());
        wrapper.set("reception",meetingSign.getReception());
        wrapper.set("receptionnumber",meetingSign.getReceptionnumber());
        wrapper.set("accompany",meetingSign.getAccompany());
        wrapper.set("accompanynumber",meetingSign.getAccompanynumber());
        wrapper.set("support",meetingSign.getSupport());
        wrapper.eq("id",meetingSign.getId());
        wrapper.set("status","0");
        wrapper.eq("status","-1");
        return meetingSignDao.update(wrapper)>0;
    }
    //删除会议招待信息
    public boolean deletemeetingsign(Integer id){
        return meetingSignDao.deleteById(id)>0;
    }
    //会议招待审核
    public  boolean manupdatestatus(MeetingSign meetingSign){
        return meetingSignDao.manupdatestatus(meetingSign)>0;
    }
}
